Repository navigation
fix(sdk-coin-flrp): bind exported output owners and change outputs to the wallet - #10211
prithvishet2503 wants to merge 1 commit into
Conversation
|
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
@claude review this PR and Score it |
|
Claude finished @prithvishet2503's task in 21s —— View job Review of PR #10211: bind exported output owners and change outputs to the walletScore: 8/10. Approve with minor suggestions. I read the diff and did not run the test suite. What the PR does
The fix addresses the stated exploit directly. It is small, well commented, and the fail-closed default is correct. Findings
Positives
VerdictThe change is correct for the described threat and safe to merge once the nit and the mixed-owner test are addressed. The locktime and threshold gap and the C→P residual should be tracked as follow-ups. |
e010916 to
947bce4
Compare
|
@claude review this PR and Score it |
|
Claude finished @prithvishet2503's task in 18s —— View job Review of PR #10211: bind exported output owners and change outputs to the walletScore: 7.5/10. Good fix for the stated threat, with one trust-anchor gap to consider. I read What it does
This closes the CECHO-2716 path where an attacker-owned output passes the amount check. The code is small and commented, it fails closed, and the tests cover the earlier review's gaps (mixed owners, locktime, empty change). Findings
Positives
VerdictMerge-worthy for the stated scenario after the nit. I'd resolve finding 1 first, either by anchoring to the keychains or by documenting the trust assumption. Findings 2, 3 and 5 are reasonable follow-ups. |
947bce4 to
b5d5aa8
Compare
|
@claude review this PR and score it |
|
Claude finished @prithvishet2503's task in 26s —— View job Review of PR #10211: bind exported output owners and change outputs to the walletScore: 8/10. Approve, with one thing to confirm before merge. I read the diff and the surrounding What changed since the earlier reviews
Findings
Positives
VerdictThis closes the stated exploit. I'd confirm finding 1 against a real MPC wallet before merging. Findings 2 and 3 should be follow-up tickets. |
b5d5aa8 to
a325314
Compare
| const keyIds = wallet.keyIds(); | ||
| if (keyIds.length === 0) { | ||
| return new Set(); | ||
| } | ||
| const keychains = await Promise.all(keyIds.map(async (keyId) => wallet.baseCoin.keychains().get({ id: keyId }))); | ||
| // A keychain without a pub makes the derived owner set incomplete — fail closed | ||
| // (the caller rejects when the set is empty) rather than verify against partial keys. | ||
| if (keychains.some((keychain) => typeof keychain.pub !== 'string')) { | ||
| return new Set(); | ||
| } |
There was a problem hiding this comment.
🔴 TSS FLRP wallets, the coin's default type, can no longer verify any P-to-C export after this change; the base branch verified them. Their keychains carry commonKeychain and no pub. So the typeof keychain.pub !== 'string' check at flrp.ts:273 returns an empty set, and validateExportTx throws 'Unable to verify P-chain export: could not derive the wallet owner set from keychains'. Fix: for TSS keychains, derive the single owner address from commonKeychain (as wallet.ts:2044-2048 does with EcdsaUtils.getPublicKeyFromCommonKeychain), and keep the per-key pub path for multisig. Add a test that uses a real TSS-shaped keychain.
Why this was flagged
Flrp.getDefaultMultisigType() returns multisigTypes.tss (flrp.ts:86-88), and getMPCAlgorithm() is 'ecdsa'. ECDSA MPCv2 keychains are created with only commonKeychain and no pub (ecdsaMPCv2.ts:462-471, keyType 'tss'). sdk-core wallet.ts:2042 says only one of pub/commonPub/commonKeychain is present. For a P-to-C export through verifyTransaction, validateExportTx calls deriveWalletOwnerSetFromKeychains (flrp.ts:236). That fetches the 3 TSS keychains, finds no string pub at flrp.ts:273 and returns an empty Set, and flrp.ts:237-238 then throws. On the base branch the same prebuild passed the amount-only check, so every TSS wallet's P-to-C export (the default wallet type) now fails before signing. The unit tests do not catch this because the keychainWallet mock (test/unit/flrp.ts:24-36) returns a synthesized pub per key, which real TSS keychains never have. The PR also notes that the MPC builder pays a single 1-of-1 owner address. Any fix therefore has to derive one address from the common key, not one address per keyId.
Verification: Trigger: any P-to-C export from an FLRP TSS/MPCv2 wallet. MPCv2 keychains are created with no pub (ecdsaMPCv2.ts:462-471), so flrp.ts:273 returns an empty set and validateExportTx throws. On the base branch, validateExportTx only checked the amount and passed. The new tests only use a keychainWallet mock that returns { pub } (test/unit/flrp.ts:25-36).
There was a problem hiding this comment.
The latest push brings this issue back at modules/sdk-coin-flrp/src/flrp.ts:279-283:
🔴 Real TSS FLRP wallets still cannot verify any P-to-C export; the new commonKeychain fallback throws 'Unsupported public key' instead of deriving an owner. A real ECDSA commonKeychain is the 33-byte public key followed by the 32-byte chaincode (130 hex chars). flrp.ts:283 passes that whole string to KeyPair({ pub }), which rejects it. Fix: take the public key from commonKeychain.slice(0, 66), as sdk-core's ecdsa base.ts:53 does. The derived address must match what the MPC builder actually pays. Also make the test mock use a real-shaped commonKeychain (pub plus chaincode).
Why this was flagged
Trigger: a P-to-C export verified through verifyTransaction for a TSS/MPCv2 wallet, the coin's default type. Its keychains carry only commonKeychain (ecdsaMPCv2.ts:462-466, keyType 'tss'). deriveWalletOwnerSetFromKeychains at flrp.ts:279 picks keychain.commonKeychain. Then flrp.ts:283 calls new FlrpLib.KeyPair({ pub }) on the 130-hex string. keyPair.ts recordKeysFromPublicKey gets 65 bytes from ECPair.fromPublicKey, which is not a valid point, and the cb58Decode fallback also fails, so it throws 'Unsupported public key'. Verification aborts and the user cannot sign the export. On the base branch, the amount-only check passed these exports. The new TSS unit test (test/unit/flrp.ts:27-36, 592-613) does not catch this. Its mock puts a bare 66-char compressed pub into commonKeychain, a shape real keychains never have. sdk-core reads only the first 66 chars of commonKeychain (utils/tss/ecdsa/base.ts:53).
Verification: flrp.ts:283 then passes that whole string to new FlrpLib.KeyPair({ pub: pub as string }). The code therefore throws 'Unsupported public key'. On the base branch, validateExportTx only checked the amount, so these exports verified; after this change every TSS P-to-C export fails before signing. The new test at test/unit/flrp.ts:592-612 hides the bug.
There was a problem hiding this comment.
The latest push brings this issue back at modules/sdk-coin-flrp/src/flrp.ts:333-346:
🔴 If FLRP TSS wallets hold funds at an HD-derived address, every legitimate P-to-C export from them is rejected. This includes 'm/0', the BitGo ECDSA TSS default. The base branch verified these exports. deriveWalletOwnerSetFromKeychains turns the root commonKeychain key straight into an address with KeyPair.getAddress and applies no HD derivation. sdk-core derives TSS addresses with deriveUnhardened at m/{index}, or {prefix}/{index} for SMC wallets. Fix: build the anchor from the commonKeychain derived at the wallet's real path (deriveMPCWalletAddress, including the derivedFromParentWithSeed prefix), not from the root key.
Why this was flagged
The condition, which this checkout cannot settle, is that FLRP TSS wallet UTXOs sit on an HD-derived address. That is the BitGo ECDSA TSS convention: deriveMPCWalletAddress (addressVerification.ts:87-91) derives m/${index} or ${prefix}/${index} via MPC.deriveUnhardened. For such an export, validateExportTx calls deriveWalletOwnerSetFromKeychains (flrp.ts:283). That function cuts the root 33-byte key out of commonKeychain (flrp.ts:338) and hashes it into an address (flrp.ts:346) without derivation. The export output and change are owned by the derived address, so requireWalletOwnedAddresses throws Export output pays non-wallet address ..., and the user cannot sign the export. On the base branch this path checked only the amount and verified. The unit tests do not catch it: the keychainWallet mock (test/unit/flrp.ts:29-36) builds commonKeychain as the raw pub plus a zero chain code, and the MPC builder fixture pays the root-key address directly.
Verification: Trigger: an FLRP TSS wallet whose P-chain UTXOs sit on an HD-derived address. deriveWalletOwnerSetFromKeychains (flrp.ts:333-338) takes the root compressed key, and flrp.ts:345 then does new FlrpLib.KeyPair({ pub }).getAddress(networkType) with no deriveUnhardened at any path. On the base branch, validateExportTx did no ownership check, so these exports verified.
|
@claude review this PR and Score it |
|
Claude finished @prithvishet2503's task in 30s —— View job Review of PR #10211: bind exported output owners and change outputs to the walletScore: 7.5/10. The design is sound and closes the stated exploit, but one blocker should be confirmed before merge. I read the full diff and What improved since earlier rounds
Findings
Tests
VerdictFix finding 1 and give it a realistic test, and this is ready to merge. Everything else is a reasonable follow-up. |
There was a problem hiding this comment.
Still open from earlier reviews (2):
- 🔴
modules/sdk-coin-flrp/src/flrp.ts:275—TSS FLRP wallets, the coin's default type, can no longer verify any P-to-C export after this change; the base branch ve… - Also unresolved: 1 minor or pre-existing.
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
2a47a1e to
6145033
Compare
… the wallet Flrp.validateExportTx checked only the exported amount window and a loose address format — never that the exported output is owned by the wallet, and never the P-chain export's change outputs. A compromised platform could serve a prebuild spending the wallet's UTXOs whose exported TransferOutput is owned by an attacker address and/or whose baseTx change output pays the attacker; verification passed and the MPC flow signed the theft (CECHO-2716). - P→C export (pvm.ExportTx): the exported output and every P-chain change output (baseTx.outputs) must be wallet-owned — each owner address must be one of the wallet's own addresses (rootAddress or receiveAddress anchor, subset containment). Fails closed when no wallet anchor is available. - C→P export (evm.ExportTx): the exported P-chain destination owner set is bound to the recipient's named address when supplied (normalized, order- and case-insensitive). An empty placeholder leaves nothing client-side to compare, matching the destination-less flow. - The SDK's own P→C builder pays the wallet's fromAddresses for both the export output and change, so the wallet-owned requirement cannot false-reject builder-produced transactions. Ticket: CECHO-2716
6145033 to
d51e125
Compare
|
@claude review this PR and Score it in detail |
|
Claude finished @prithvishet2503's task in 28s —— View job Review of PR #10211 (CECHO-2716): bind exported output owners and change outputs to the walletScore: 7/10. The design is strong and most earlier findings are fixed, but there is one new bypass to fix before merge. I read the full Blocker: the one-output guard was deleted, so only
|
There was a problem hiding this comment.
Still open from earlier reviews (1):
- 🔴
modules/sdk-coin-flrp/src/flrp.ts:344—TSS FLRP wallets, the coin's default type, can no longer verify any P-to-C export after this change; the base branch ve…
If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.
| ); | ||
| } | ||
| } | ||
| } else { | ||
| // P→C export: the SDK builder pays the wallet's own addresses both for the | ||
| // exported output and for the P-chain change (baseTx.outputs) — the C destination | ||
| // is the wallet's paired C address. Require both to be wallet-owned so an | ||
| // attacker-owned export output or redirected change fails verification | ||
| // (CECHO-2716). | ||
| // | ||
| // The owner anchor is DERIVED FROM THE WALLET'S KEYCHAINS (client-verified key | ||
| // material, the same derivation isWalletAddress uses) — not from platform-served | ||
| // wallet fields: a compromised platform controls the prebuild AND | ||
| // rootAddress/receiveAddress, so those cannot anchor the ownership check. | ||
| // Fail closed when the keychain-derived owner set is unavailable. | ||
| const anchorOwners = await this.deriveWalletOwnerSetFromKeychains(params.wallet); | ||
| if (anchorOwners.size === 0) { | ||
| throw new Error('Unable to verify P-chain export: could not derive the wallet owner set from keychains'); | ||
| } | ||
| this.requireWalletOwnedAddresses('Export output', explainedTx.outputs[0].address, anchorOwners); |
There was a problem hiding this comment.
🔴 A compromised platform can again steal a whole P-to-C or C-to-P export by adding a second exported output. The base branch rejected this. The diff dropped the explainedTx.outputs.length !== 1 guard. Ownership (flrp.ts:287) and the C-to-P destination check (flrp.ts:264-265) still read only explainedTx.outputs[0]. Fix: check every exported output, or restore the exactly-one-output rule, and throw a clear error when outputs is empty. Same pattern at 3 sites (flrp.ts:249, flrp.ts:264, flrp.ts:287).
Why this was flagged
A malicious pvm.ExportTx prebuild reaches verifyTransaction (flrp.ts:149) and then validateExportTx. It has two outs: outs[0] pays 1 nFLR to the wallet owner set, and outs[1] pays almost all of recipients[0].amount to an attacker. Transaction.outputs (transaction.ts:479) maps every outs entry, and outputAmount (transaction.ts:602) sums them, so the amount window at flrp.ts:240-243 passes. requireWalletOwnedAddresses runs only on explainedTx.outputs[0].address (flrp.ts:287). validateExportOutputPolicy checks only locktime and threshold, and validateExportFee counts the attacker output as payout, so neither catches it. The user co-signs and the attacker imports the exported value. The C-to-P branch has the same hole: only outputs[0] is compared to the recipient destination (flrp.ts:264-265). On the base branch, if (recipients.length !== 1 || explainedTx.outputs.length !== 1) throw new Error('Export Tx requires one recipient') rejected any multi-output export. With zero outputs, explainedTx.outputs[0].address at flrp.ts:249 now throws a TypeError instead of that error.
Verification: Trigger: a compromised platform returns an export prebuild with two or more exported outputs. The base rejected this, and the diff deletes that guard from validateExportTx. P→C: the ownership check only reads the first output (flrp.ts:287). C→P: the destination check compares only explainedTx.outputs[0].address (flrp.ts:264-265).
|
@claude review this PR and Score in detail |
|
Claude finished @prithvishet2503's task in 27s —— View job Review of PR #10211 (CECHO-2716): bind exported output owners and change outputs to the walletScore: 7/10. The design is sound and most earlier findings are fixed, but one bypass needs fixing before merge. I read the full Blocker: the one-output guard was deleted, so only
|
Problem
Flrp.validateExportTx validated only the exported amount window and a loose address format regex. It never verified that the exported output is owned by the wallet, never inspected the P-chain export's change outputs
(pvmSerial.ExportTx.baseTx.outputs, surfaced as explainedTx.changeOutputs), and never bounded the implied burned fee.
Exploit: A compromised platform returns a pvm.ExportTx prebuild that spends the wallet's UTXOs but whose exported TransferOutput is owned by an attacker address and/or whose baseTx change output pays the attacker and/or burns most of the
spent UTXOs as fee. verifyTransaction passes; the MPC flow signs the digest over exactly these verified-but-malicious bytes; the attacker imports the atomic UTXO to their own address — full theft of the exported amount plus redirected change
or burned remainder. This coin-level gap is independent of the sdk-core pre-hashed-digest finding: the verified serializedTxHex itself is never checked for destination ownership.
Fix
P→C export (pvm.ExportTx) — the ticket's exploit path. Four bindings on every verification:
from keychain public keys — the exact derivation isWalletAddress performs. Accepts keychain.pub, falling back to EcdsaUtils.getPublicKeyFromCommonKeychain(keychain.commonKeychain) for TSS/MPC keychains (130-hex-char pub+chaincode; a malformed
length throws Invalid commonKeychain length, expected 130 and fails closed). Platform-served wallet fields (rootAddress/receiveAddress) are deliberately not trusted as anchors. A foreign owner — even a single attacker address inside a
wallet-majority mixed set — throws. Fails closed when the owner set can't be derived.
to wallet configuration — no authoritative expected threshold reaches verifyTransaction; the keychain-derived wallet-ownership requirement is what prevents platform-controlled theft. Pinning owner set/threshold by wallet type is tracked as
CECHO-2868.
own fee-model exports and P-chain protocol fee weights {bandwidth:1, dbRead:1000, dbWrite:1000, compute:4}; GAS_PRICE_CEILING = 1000 nFLR (~4× the observed network price). A flat cap would false-reject legitimate many-input exports — the
P-chain dynamic fee grows linearly with input count (~1M nFLR per 2-of-3 input at price 251, so ≥10 inputs exceed the flat 10M maxImportFee) — while the flat maxImportFee remains the floor so the dust-change attack is still caught. Non-finite
totals fail closed.
— none of the four bindings reject builder-produced transactions.
C→P export (evm.ExportTx): The exported P-chain destination owner set is bound to recipients[0].address when supplied (normalized comparison); a substituted destination throws. An empty recipient leaves the destination unbound — C→P
destinations can be legitimate external P owner sets held server-side, so wallet-binding would false-reject cross-wallet exports. Tracked as CECHO-2867.
Issue Number
Ticket: CECHO-2716
Follow-ups: CECHO-2867, CECHO-2868, CECHO-2808
Type of change
How Has This Been Tested?
Ground truth established first via real parse-path probes and builder experiments: EXPORT_IN_P (P→C) pays the wallet's 3-address owner set for both the exported output and the change; EXPORT_IN_C (C→P) pays an external 3-address P owner set
with no change outputs; the fixture export's gas is 9125 (fee ≈ 2.29M nFLR at price 251) and flarejs's getTxComplexity/dimensionsToGas reproduce it — each fact drove the test design, the builder-safety argument, and the fee-ceiling
calibration.
16 new tests in modules/sdk-coin-flrp/test/unit/flrp.ts:
P→C ownership (keychain-derived anchor):
P→C spend policy:
11. Future-locktime output → throws Export output locktime … must be 0
12. Full-spend export with no change outputs → verifies cleanly
P→C burned-fee bound (complexity-scaled):
13. 29.5M burned vs fixture-tx ceiling (~19.1M) → throws Export burns … exceeding the complexity-scaled fee bound
14. Fixture-shaped ~1.31M fee → passes
15. 10-input consolidation export burning ~11M (above old flat 10M cap, within scaled ceiling) → verifies (pins the flat-cap false-reject is gone)
C→P destination:
16. Correct external destination (different address order) → true; attacker destination → throws
Reproduce:
cd modules/sdk-coin-flrp
BITGOJS_TEST_PASSWORD=testpassword yarn unit-test
424 passing, 0 failing
Also verified: module tsc build clean, eslint --quiet clean, prettier --check clean. All master-merged CECHO-2717 import/delegation tests green alongside this branch's export tests.
Checklist
direction-specific bindings, fee-weights/gas-price-ceiling constants, CECHO-2867/2868 residual links, and threshold residual)